import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-07-02
 * Time: 21:16
 */
public class test2 {
    public boolean hasCycle(ListNode head) {
        if(head==null){
            return false;
        }
        Set<ListNode> set = new HashSet<ListNode>();
        ListNode cur = head;
        while(cur!=null){
            if(!set.add(cur)){
                return true;
            }
            cur = cur.next;
        }
        return false;
    }


    class ListNode{
        ListNode next;
    }
}
